<?
$isReloadable = true;
$isPopUp = true;
require_once("../../pers/inc.config.php");
require_once(OVF_FS_WEB_ROOT.'/app/_inc/inc.session.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.html.php');
require_once(OVF_FS_WEB_ROOT.'/app/_inc/funct.ricercaAnag.php');
$aAnag=array();
if (isset($_GET['anag'])) {
   $_REQUEST['anag'] = utf8_decode(reqVar('anag'));
}
if (reqVarTrim('anag')=='') {
   $msgPag .= 'digita aleno 3 crt. per la ricerca';
} else {
   $msgPag .= ricercaAnag(reqVar('anag'),$aAnag);
}
reqDef('cex', 'C');

$aOpt = array("width"=>480);
echo getTestaPopUpHtml("Ricerca anagrafica",$msgPag, $aOpt);
?>
<script>
function setAnagForm(val) {
	if ('<?=reqVar('nome_form')?>'=='') {
		alert("manca nome form !");
		return false;
	}
	if ('<?=reqVar('nome_campo')?>'=='') {
		alert("manca nome campo!");
		return false;
	}
	oFormOrig = window.opener.document.<?=reqVar('nome_form')?>;
	nomeCampo = '<?=reqVar('nome_campo')?>';
	if (!oFormOrig) {
		alert('finestra origine mancante');
		window.close();
		return false;
	}
	for($k=0; $k < oFormOrig.elements.length; $k++) {
		if (oFormOrig.elements[$k].name == nomeCampo) break;
	}
	if ($k >= oFormOrig.elements.length) {
		alert('non esiste campo '+nomeCampo);
		window.close();
		return false;
	}
	oField = oFormOrig.elements[$k];
	oField.value = val;
	
	//alert(nomeCampo+'='+val);
	oField.focus();
	window.close();
	return true;
}
</script>
<form name="frmNorm" id='frmNorm' action="<?=$_SERVER['PHP_SELF']?>" method="POST">
<input type="hidden" name="azione" value="xxx">
<input type="hidden" name="xsn" value="<?=XSN?>">
<input type="hidden" name="nome_form" value="<?=reqVarHE('nome_form')?>">
<input type="hidden" name="nome_campo" value="<?=reqVarHE('nome_campo')?>">
<table width='100%' cellspacing='1' cellpadding='2' border='0'>
   <tr>
      <td class='cmd1' align='left' colspan='2'>
         Parole da cercare:&nbsp;<?=getHtmlText('anag',30,60)?>
         &nbsp;
         <a class='cmd1' href='javascript:document.frmNorm.submit();'>ricerca</a>
      </td>
      <td class='cmd1' align='right' >
          <a class='cmd1' href='javascript:window.opener.focus();window.close();'>chiudi</a>
      </td>
  </tr>
   <tr>
      <td colspan="3" class='tit1' align='center'>Anagrafiche trovate</td>
   </tr>
   <tr>
      <td class='lab1' align='center' width='5%'>&nbsp;</td>
      <td class='lab1' align='center' width='90%'>Intestazione</td>
      <td class='lab1' align='center' width='5%'>Id.</td>
   </tr>
<?
foreach($aAnag as $idAnaX => $sIntX) {
?>
   <tr>
      <td class='txt1' align='left' style='padding:0 5 0 5;'>
      	<a href='#' 
      		onClick="setAnagForm('<?=addslashes($sIntX)." (".$idAnaX.")"?>')" class='txt1'>
      		seleziona
      	</a>
      </td>
      <td class='txt1' align='left'><?=$sIntX?></td>
      <td class='txt1' align='center'><?=$idAnaX?></td>
   </tr>
<?	
}
?>
   <tr>
      <td colspan="3" class='cmd1' align='right'>
			<a class='cmd1' href='javascript:window.opener.focus();window.close();'>chiudi</a>
		</td>
   </tr>
</table>
</form>	  	   	   
<?
echo getCodaPopUpHtml();
exit;